package com.wxg.common.redis.filter;

import java.util.BitSet;

/**
 * @author void
 * @date 2019/12/31 9:41
 * @desc
 */
public class BloomFilter {

    private final int size;

    private final BitSet bitSet;

    public BloomFilter(int size){
        this.size = size;
        bitSet = new BitSet(size);
    }

    public void addValue(String value){
        bitSet.set(Math.abs(value.hashCode()));
    }

    public boolean exists(String value){
        return bitSet.get(Math.abs(value.hashCode()));
    }

//    public static void main(String[] args) {
//        BloomFilter filter = new BloomFilter(1000);
//        filter.addValue("www.baidu.com");
//        filter.addValue("www.bilibili.com");
//        System.out.println(filter.exists("www.wxg123.com"));
//        System.out.println(filter.exists("www.baidu.com"));
//    }
}
